package com.springboot.controller;

import com.springboot.domain.Student;
import com.springboot.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "/mylogin")
    public String Login(){
        return "myAjax";
    }

    @RequestMapping(value = "/hello")
    public String hello(){
        return "index";
    }

    @RequestMapping(value = "stu.do")
    public ModelAndView getById(Integer id){
        ModelAndView mv = new ModelAndView();
        Student student = studentService.getById(id);
        mv.addObject("student", student);
        mv.setViewName("studentDetail");
        return mv;
    }


    @RequestMapping(value = "getAll")
    public ModelAndView getAll(){
        ModelAndView mv = new ModelAndView();
        List<Student> sList = studentService.getAll();
        mv.addObject("sList", sList);
        mv.setViewName("studentDetail");
        return mv;
    }

}
